package com.gitee.springioc.service.impl;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.BeansException;
import org.springframework.beans.MutablePropertyValues;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;

/**
 * @author ming.yan-1
 * @version V1.0
 * @Title com.gitee.springioc.service.impl
 * @Description
 * @date 2018/9/14  上午11:17
 */
public class OrderBeanFactoryPostProcessor implements BeanFactoryPostProcessor {

    private static final Log logger = LogFactory.getLog(OrderBeanFactoryPostProcessor.class);

    @Override
    public void postProcessBeanFactory(ConfigurableListableBeanFactory configurableListableBeanFactory) throws BeansException {
        logger.info("into OrderBeanFactoryPostProcessor postProcessBeanFactory method");
        String[] beanDefinitionNames = configurableListableBeanFactory.getBeanDefinitionNames();
        BeanDefinition beanDefinition = null;
        Object bean = null;
        boolean isChange;
        for(String beanDefinitionName:beanDefinitionNames){
            beanDefinition = configurableListableBeanFactory.getBeanDefinition(beanDefinitionName);
//            logger.info("print beanDefinition info BeanClassName->"+beanDefinition.getBeanClassName()+" Description->"+beanDefinition.getDescription());
            MutablePropertyValues mutablePropertyValues = beanDefinition.getPropertyValues();
            isChange = ("OrderService").equals(beanDefinitionName);
//            isChange = ("com.gitee.springioc.service.impl.OrderServiceImpl").equals(beanDefinition.getBeanClassName());
//            isChange = mutablePropertyValues.contains("str")
            if(isChange){
                mutablePropertyValues.addPropertyValue("str","BeanFactoryPostProcessor");
            }
        }
    }
}
